<%--
    Document   : home
    Created on : 09.12.2011, 11:43:02
    Author     : Дима
--%>

<%@page import="encaps.resources.Labels"%>
<%@page import="encaps.utils.rendering.PageHeaderBuilder"%>
<%@page import="encaps.resources.Config"%>
<%@page import="encaps.utils.rendering.Renderer"%>
<%@page import="org.jdom.Element"%>
<%@page import="encaps.utils.EntityUtil"%>
<%@page import="encaps.utils.InitializationException"%>
<%@page import="encaps.utils.rendering.SideBarBuilder"%>
<%@page import="encaps.action.ActionContext"%>
<%@page import="encaps.utils.ActionExecutor"%>
<%@page import="javax.naming.*"%>
<%@page import="encaps.action.Action"%>
<%@page import="java.util.*"%>
<%@page import="encaps.utils.RequestParser"%>
<%@page import="encaps.entities.*"%>
<%@page import="encaps.utils.StringUtil"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <link rel="stylesheet" type="text/css" href="css/style.css"/>
        <%!
        public static final String USER_ROLE = "role";
        public RequestParser requestParser;
        public SideBarBuilder sideBarBuilder;


        public void init() throws ServletException {
            try {
                requestParser = new RequestParser();
                sideBarBuilder = new SideBarBuilder();
            } catch(Exception ex) {
                throw new ServletException(ex);
            }
        }
        %>

        <%
        String roleName = (String) session.getAttribute(USER_ROLE);
        if(StringUtil.isEmpty(roleName)) {
            roleName = Role.GUEST;
            session.setAttribute(USER_ROLE, roleName);
        }
        ActionContext c = new ActionContext(request);
        Action action = requestParser.parseRequest(c);
        Element resultXML = ActionExecutor.executeAction(roleName, action);
        String result = Renderer.renderResult(resultXML);
        %>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>EMDB</title>
        <script type="text/javascript" src="script/script.js"></script>
    </head>

    <body>
        <div class="container">
            
            <div class="pageHeader">
                <%= PageHeaderBuilder.createPageHeader() %>
            </div>
            <div class="sideBar">
            <%= sideBarBuilder.createSideBar((String) session.getAttribute("user")) %>
            </div>
            <div class="content">
                <form action="home.jsp" method="post" enctype="multipart/form-data">
                    <%= result %>
                </form>
            </div>
        </div>
        <div class="footer">
            <%= Labels.getLabel(Labels.FOOTER_STATEMENT) %>
        </div>        
    </body>
</html>
